##
## Wizard.py 
##
## Class which walks users through normal cwsAdmin usage
##
## Author: Shannon Eric Peevey <speeves@erikin.com>, 26 Nov 2006
##

# Try to import the optional modules
try:
    from Mssql import *
except ImportError:
    pass
try:
    from Mysql import *
except ImportError:
    pass
try:
    from Htgroup import *
except ImportError:
    pass
try:
    from Webcontrol import *
except ImportError:
    pass
try:
    from Email import *
except ImportError:
    pass
try:
    from Postgresql import *
except ImportError:
    pass
try:
    from Analog import *
except ImportError:
    pass
try:
    from Ldap import *
except ImportError:
    pass
try:
    from Utility import *
except ImportError:
    pass


class WizardFunc:
    """ Class of functions which walk users through usual setups (ie apache web, mysql db, ldap user mgmt, and email notifications """
	
    def AddWizard(self, config, menu, errorObject, utilityObject):
        """ Create apache subweb, mysql database, ldap user mgmt, and email notification """

        # create apache object
        a = ApacheFunc()

        # create subweb, or vhost
        subwebVhost = raw_input("[s]ubweb/[v]host/[n]one? [s] ")
        if subwebVhost == "":
            subwebVhost = "s"

        if subwebVhost == "s":
            ## call create subweb function
            a.CreateWeb(config, errorObject, utilityObject)
        elif subwebVhost == "v":
            ## call create subweb function
            a.CreateVHost(config, errorObject, utilityObject)
        else:
            pass
        
        del a

        # create ldap object
        l = LdapFunc()

        # should I search first?
        searchFirst = raw_input("Would you like to do a LDAP search first? (y/[n]) ")
        if searchFirst == "":
            searchFirst = "n"

        if searchFirst != "n":
            l.LdapSearchInterface(config, utilityObject)

        # perform user add to group
        searchFirst = raw_input("Add LDAP user to group? ([y]/n) ")
        if searchFirst == "":
            searchFirst = "y"

        if searchFirst == "y":
            l.LdapAddUser(config, utilityObject)
        del l

        # mysql/mssql?
        mysqlMssql = raw_input("Create M[y]SQL/M[s]SQL db, or [n]one? ([y]/s/n) ")
        if mysqlMssql == "":
            mysqlMssql = "y"

        if mysqlMssql == "y":
            # create mysql db and user rights
            my = MysqlFunc()
            my.AddMysqlDatabase(config, utilityObject)
            my.AddMysqlUser(config, utilityObject)
            del my
        elif mysqlMssql == "s":
            # create mssql db and user rights
            ms = MssqlFunc()
            ms.AddMssqlDatabase(config, utilityObject)
            ms.AddMssqlUser(config, utilityObject)
            del ms
        else:
            pass

        # generate welcome email
        genEmail = raw_input("Generate a Welcome Email? ([y]/n) ")
        if genEmail == "":
            genEmail = "y"

        if genEmail == "y":
            e = EmailFunc()
            e.RunEmail(config, utilityObject)
            del e
